package com.clkj.goldpartner.dao;

import com.clkj.goldpartner.pojo.Supplier;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 杨行
 * @date 2021/3/1 15:18
 */
@Repository
public interface SupplierMapper extends Mapper<Supplier> {

    /**
     * 获取供货商
     *
     * @param shop_id
     * @param supplier_name
     * @param supplier_num
     * @return List<Supplier>
     */
    @Select("select * from t_cl_supplier where shop_id = #{shop_id} and supplier_status = '0' and supplier_name like '%${supplier_name}%' and supplier_num like '%${supplier_num}%'")
    List<Supplier> getSupplier(Integer shop_id, String supplier_name, String supplier_num);

    /**
     * 获取可用供货商
     *
     * @param shop_id
     * @param supplier_name
     * @param supplier_num
     * @return List<Supplier>
     */
    @Select("select * from t_cl_supplier where shop_id = #{shop_id} and supplier_status = '0' and licence_date >= getDate() and busLicence_date >= getDate() and GMP_date >= getDate() and code_date >= getDate() and supplier_name like '%${supplier_name}%' and supplier_num like '%${supplier_num}%'")
    List<Supplier> getSupplierNow(Integer shop_id, String supplier_name, String supplier_num);

    /**
     * 删除供货商
     *
     * @param ids
     */
    @Update("update t_cl_supplier set supplier_status = '1' where supplier_id in (${ids})")
    void deleteSupplier(@Param("ids") String ids);

    /**
     * 获取最后一位编号
     *
     * @return String
     */
    @Select("select top 1 supplier_num from t_cl_supplier group by supplier_id,supplier_num order by supplier_id desc ")
    String getSupplier_num();

    /**
     * 获取过期代理商
     *
     * @param shop_id
     * @return
     */
    @Select("select * from t_cl_supplier where shop_id = #{shop_id} and ( datediff(day,getDate(),licence_date) <= 60 or datediff(day,getDate(),busLicence_date) <= 60 or datediff(day,getDate(),GMP_date) <= 60 or datediff(day,getDate(),code_date) <= 60 )")
    List<Supplier> getSupplierWarn(Integer shop_id);
}
